Dart BigInt operator ^
Syntax & Examples
BigInt.operator ^ operator
The `operator ^` in Dart performs a bitwise exclusive-or operation between two BigInt objects.
Syntax of BigInt.operator ^
The syntax of BigInt.operator ^ operator is:
operator ^(BigInt other) → BigIntThis operator ^ operator of BigInt bit-wise exclusive-or operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the BigInt object to perform the bitwise exclusive-or operation with |
✐ Examples
1 Perform bit-wise XOR operation
In this example,
- We create two BigInt objects,
num1andnum2, initialized with different values. - We use the
^operator to perform a bit-wise exclusive-or operation betweennum1andnum2. - We print the result of the operation to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(10);
BigInt num2 = BigInt.from(7);
BigInt result = num1 ^ num2;
print('Bit-wise XOR of num1 and num2: $result');
}Output
Bit-wise XOR of num1 and num2: 13
2 Perform bit-wise XOR operation with hexadecimal numbers
In this example,
- We create two BigInt objects,
num1andnum2, initialized with hexadecimal values. - We use the
^operator to perform a bit-wise exclusive-or operation betweennum1andnum2. - We print the result of the operation to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(0x55);
BigInt num2 = BigInt.from(0xAA);
BigInt result = num1 ^ num2;
print('Bit-wise XOR of num1 and num2: $result');
}Output
Bit-wise XOR of num1 and num2: 171
3 Perform bit-wise XOR operation with binary numbers
In this example,
- We create two BigInt objects,
num1andnum2, initialized with binary values. - We use the
^operator to perform a bit-wise exclusive-or operation betweennum1andnum2. - We print the result of the operation to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(0b1100);
BigInt num2 = BigInt.from(0b1010);
BigInt result = num1 ^ num2;
print('Bit-wise XOR of num1 and num2: $result');
}Output
Bit-wise XOR of num1 and num2: 6
Summary
In this Dart tutorial, we learned about operator ^ operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.